package com.xzjt.web.controller;


import com.xzjt.common.utils.R;
import com.xzjt.web.entity.MenuTree;
import com.xzjt.web.entity.SysMenu;
import com.xzjt.web.service.SysMenuService;
import com.xzjt.web.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: SysMenuController
 * @Author: yuandong
 * @Date 2021/10/11 9:15
 * 菜单Controller
 */
@RestController
@RequestMapping("/sys")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;
    @Autowired
    private SysUserService sysUserService;

    /**
     * 查询所有菜单(并构建树形结构)
     * @return
     */

    @GetMapping("/menuTree/{id}")
    public R getMenuTree(@PathVariable Integer id){


        List<SysMenu> menus = sysMenuService.selectMenuList(id);


        MenuTree menuTree=new MenuTree(menus);
        List<SysMenu> menuList = menuTree.builTree();
        return R.ok(menuList);
    }

    /**
     * 查询用户对应的菜单
     * @param userId
     * @return
     */
    public R getMenuTreeByUser(Integer userId){
        return R.ok();
    }



}
